﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Presentation.Models.ProjectViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit <%: Model.Project.Name %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Edit <%: Model.Project.Name %></h2>
    <!--<font style="color: #FF0000"><b><%: Model.errmsg %></b></font>-->

    <% using (Html.BeginForm("Edit", "Project", FormMethod.Post))
       {%>

                <div>
                
                    <table>
                        
                        <tr>
                            <td>
                                 <%: Html.LabelFor(m => m.Project.Name) %>
                            </td>
                            <td>
                                <%: Html.TextBoxFor(m => m.Project.Name)%>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <%: Html.LabelFor(m => m.Project.Description)%>
                            </td>
                            <td>
                                <%: Html.TextBoxFor(m => m.Project.Description)%>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%: Html.LabelFor(m => m.Project.Status)%>
                            </td>
                            <td>
                                <%: Html.Hidden("Project.Status.Id", Model.Project.Status.Id) %>
                                <%: Html.DropDownListFor(m => m.Project.Status.StatusIndicator, Model.StatusItems)%>
                            </td>
                        </tr>

                        <% 
           
                            foreach (var formElement in Model.Form.FormElements)
                            {
                                var index = Model.Project.GetDetailIndex(formElement.Name);

                                var error = " ";

                                if (Model.errmsg != null && Model.errindex == index)
                                    error = Model.errmsg;
                                
                                if (index != -1)
                                { 
                                    var detail = Model.Project.Details[index];
                            

                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_CHAR))
                                    { 
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Project.Details[index].Name) %>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Project.Details[" + index + "].Id", detail.Id) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Name", detail.Name) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Description", detail.Description) %>
                                                <%: Html.TextBox("Project.Details[" + index + "].Value", detail.Value) %>
                                                <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_NUMERIC))
                                    {
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Project.Details[index].Name) %>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Project.Details[" + index + "].Id", detail.Id) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Name", detail.Name) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Description", detail.Description) %>
                                                <%: Html.TextBox("Project.Details[" + index + "].Value", detail.Value) %>
                                                <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                    if (formElement.Type.Equals(Domain.Model.FormElement.TYPE_DATE))
                                    {
                                    %>
                                        
                                        <tr>
                                            
                                            <td>
                                            <%: Html.Label(Model.Project.Details[index].Name) %>
                                            </td>
                                            <td>
                                                <%: Html.Hidden("Project.Details[" + index + "].Id", detail.Id) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Name", detail.Name) %>
                                                <%: Html.Hidden("Project.Details[" + index + "].Description", detail.Description) %>
                                                <%: Html.TextBox("Project.Details[" + index + "].Value", detail.Value) %>
                                                <font style="color: #FF0000"><b><%:error %></b></font> 
                                            </td>

                                        </tr>
                                        
                                    <%
                                    }
                                }
                            }
                    
                        %>

                    </table>

                <p>
                    <%: Html.Hidden("ProgramId", Model.ProgramId) %> 
                    <%: Html.Hidden("Project.Id", Model.Project.Id) %>
                    <input type="submit" value="Save" />
                </p>

        </div>

    <% } %>

    <div>
        <p>
        <% if (Model.ProgramId > 0)
           { %>
            <%: Html.ActionLink("Cancel, back to program", "View", "Program", new { id = Model.ProgramId }, null) %>
           <% }
           else
           { %>
            <%: Html.ActionLink("Cancel, back to portfolio", "Overview", "Portfolio") %>
           <% }
        %> | 
            <%: Html.ActionLink("Add Subproject", "Create", "Subproject", new { projectId = Model.Project.Id}, null) %> |
            <%: Html.ActionLink("Add Task", "AddTask", "Project", new { projectId = Model.Project.Id }, null)%>
        </p>
    </div>

    <table>
    
        <tr>

            <th>Subprojects</th>
            <th>Tasks</th>
        
        </tr>
        <tr valign="top">
            <td>
                <% Html.RenderPartial("SubprojectList", Model.Project.Subprojects); %>
            </td>
            <td>
                <% Html.RenderPartial("ProjectTaskList", Model.Project.Tasks); %>
            </td>
        </tr>

    </table>

</asp:Content>

